<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/10/10
 * Time: 9:37
 */
namespace app\admin\model;
use think\Db;
use think\Model;
class SuggestModel extends Model
{
    protected $name = 'feedback';

    public function getSuggestData($map, $Nowpage, $limits){
        $data =  $this->alias ('f')
            ->join('u_user u','f.f_user_id = u.user_id','left')
            ->join('feedback_cate c','f.f_type = c.cate_id','left')
            ->where($map)
            ->field('f_id,f_type,f_user_id,user_username,f_phone,f_time,f_content,f_status,cate_name')
            ->page($Nowpage,$limits)
            ->select();
        if(!empty($data)){
            foreach($data as $key=>$vo){
                $cate = Db::name('feedback_cate')->where('cate_id','in',$vo['f_type'])->column ('cate_name');
                $data[$key]['cate_name'] = implode ('，',$cate);
            }
        }
        return $data;
    }

    public function getSuggestCount($map){
        return $this->alias ('f')
            ->join('u_user u','f.f_user_id = u.user_id','left')
            ->join('feedback_cate c','f.f_type = c.cate_id','left')
            ->where($map)
            ->count();
    }

    public function getBusinessData($map, $Nowpage, $limits){
        return $this->alias ('f')
            ->join('shops s','f.f_user_id = s.s_id','left')
            ->where($map)
            ->field('f_id,s_name,f_time,f_content,f_status')
            ->page($Nowpage,$limits)
            ->select();
    }

    public function getBusinessCount($map){
        return $this->alias ('f')
            ->join('shops s','f.f_user_id = s.s_id','left')
            ->where($map)
            ->count();
    }

    public function getSalesmanData($map, $Nowpage, $limits){
        return $this->alias ('f')
            ->join('work_user w','f.f_user_id = w.user_id','left')
            ->where($map)
            ->field('f_id,user_name,f_time,f_content,f_status')
            ->page($Nowpage,$limits)
            ->select();
    }

    public function getSalesmanCount($map){
        return $this->alias ('f')
            ->join('work_user w','f.f_user_id = w.user_id','left')
            ->where($map)
            ->count();
    }
}